﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************

Imports GoogleWidgetEditor.CodeSnippet
Imports System.ComponentModel
''' <summary>
''' Code snippet class
''' </summary>
''' <remarks></remarks>
Public Class CodeStore
    Implements IObjectName

#Region "Enum"
    Public Enum enumScope
        [Public] = 0
        [Private] = 1
    End Enum
#End Region
#Region "Fields"
    Private _Name As String = String.Empty
    Private _Description As String = String.Empty
    Private _Code As String = String.Empty
    Private _Code2 As String = String.Empty
    Private _Example As String = String.Empty
    Private _nameSpace As String = String.Empty
    Private _RequireLib As String = String.Empty
    Private _Scope As enumScope
    Private _Parent As CodeStoreCollection
#End Region
#Region "Property"
    Protected ReadOnly Property Parent() As Object Implements IObjectName.Parent
        Get
            Return _Parent
        End Get
    End Property
    Public Sub SetParent(ByVal ParentObject As Object) Implements IObjectName.SetParent
        _Parent = ParentObject
    End Sub
    <CategoryAttribute("Misc"), Description("Example of use"), Browsable(True)> _
    Public Property Example() As String
        Get
            Return _Example
        End Get
        Set(ByVal value As String)
            _Example = value
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Location In Namespace"), Browsable(True)> _
    Public Property Name_Space() As String
        Get
            Return _nameSpace
        End Get
        Set(ByVal value As String)
            _nameSpace = value
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Name of the Code Snippet")> _
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Description of the Code Snippet")> _
    Public Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            _Description = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False), CategoryAttribute("Misc"), Description("Code of the Code Snippet")> _
    Public Property Code() As String
        Get
            Return _Code
        End Get
        Set(ByVal value As String)
            _Code = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False), CategoryAttribute("Misc"), Description("Code of the Code Snippet")> _
    Public Property Code2() As String
        Get
            Return _Code2
        End Get
        Set(ByVal value As String)
            _Code2 = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False), CategoryAttribute("Misc"), Description("Required Lib")> _
    Public Property RequireLib() As String
        Get
            Return _RequireLib
        End Get
        Set(ByVal value As String)
            _RequireLib = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False), CategoryAttribute("Misc"), Description("Share the code with the public")> _
    Public Property Scope() As enumScope
        Get
            Return _Scope
        End Get
        Set(ByVal value As enumScope)
            _Scope = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False)> _
    Public ReadOnly Property ObjectName() As String Implements IObjectName.ObjectName
        Get
            Return Me.Name
        End Get
    End Property
#End Region
#Region "Constructor"
    Public Sub New()

    End Sub
    Public Sub New(ByVal Name As String, ByVal Description As String, ByVal Code As String, ByVal Scope As enumScope)
        Me.Name = Name
        Me.Description = Description
        Me.Code = Code
        Me.Scope = Scope
    End Sub
    Public Sub New(ByVal Name As String, ByVal Description As String, ByVal Code As String, ByVal Scope As enumScope, ByVal ReqLib As String)
        Me.Name = Name
        Me.Description = Description
        Me.Code = Code
        Me.Scope = Scope
        Me.RequireLib = ReqLib
    End Sub
#End Region
#Region "Methods"
    Public Sub SetDirty()
        If Me.Parent IsNot Nothing Then Me.Parent.SetDirty()
    End Sub
#End Region
End Class


''' <summary>
''' Code snippet collection
''' </summary>
''' <remarks></remarks>
Public Class CodeStoreCollection
    Inherits ObjectModel.Collection(Of CodeStore)
    'Inherits ObjectModel.KeyedCollection(Of String, CodeStore)
    Implements IObjectName
#Region "Fields"
    Private _Parent As Widget = Nothing
    Private _IsDirty As Boolean = False
#End Region
#Region "Methods"
    ''' <summary>
    ''' Save the Project
    ''' </summary>
    ''' <param name="filename">File name and path</param>
    ''' <remarks></remarks>
    Public Sub Save(ByVal filename As String)
        Dim mlSerializer As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(GetType(CodeStoreCollection))
        Dim writer As IO.StringWriter = New IO.StringWriter()
        mlSerializer.Serialize(writer, Me)
        My.Computer.FileSystem.WriteAllText(filename, writer.ToString, False, Global.System.Text.Encoding.Default)
    End Sub
    Public Sub SetDirty()
        If Me.Parent IsNot Nothing Then Me.Parent.SetDirty()
    End Sub
    Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As CodeStore)
        MyBase.InsertItem(index, item)
        item.SetParent(Me)
    End Sub
    Public Shadows Sub Add(ByVal Name As String, ByVal Name_Space As String, ByVal Description As String, ByVal Code As String, ByVal Scope As enumScope)
        Dim Tobj As CodeStore
        Tobj = New CodeStore
        Tobj.Name = Name
        Tobj.Description = Description
        Tobj.Code = Code
        Tobj.Scope = Scope
        Tobj.Name_Space = Name_Space
        MyBase.Add(Tobj)
    End Sub
    Public Shadows Sub Add(ByVal oCodeSnippet As CodeStore)
        MyBase.Add(oCodeSnippet)
    End Sub
    'Protected Overrides Function GetKeyForItem(ByVal item As CodeStore) As String
    '    Return item.Name
    'End Function
#End Region
#Region "Constructor"
    Public Sub New()

    End Sub
#End Region
#Region "Properties"
    Public Property IsDirty() As Boolean
        Get
            Return _IsDirty
        End Get
        Set(ByVal value As Boolean)
            _IsDirty = value

        End Set
    End Property
    Protected ReadOnly Property Parent() As Object Implements IObjectName.Parent
        Get
            Return _Parent
        End Get
    End Property
    Public Sub SetParent(ByVal ParentObject As Object) Implements IObjectName.SetParent
        _Parent = ParentObject
    End Sub
    Public ReadOnly Property ObjectName() As String Implements IObjectName.ObjectName
        Get
            Return "CodeSnippets"
        End Get
    End Property
#End Region
End Class